package com.ossjk.qlh.system.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ossjk.core.base.controller.BaseController;
import com.ossjk.core.util.CommonUtil;
import com.ossjk.core.vo.RequestBean;
import com.ossjk.core.vo.ResponseBean;
import com.ossjk.qlh.loginfo.LogModule;
import com.ossjk.qlh.loginfo.LogOperation;
import com.ossjk.qlh.system.service.ILoginrecordService;
import com.ossjk.qlh.system.vo.LoginrecordVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 登录记录表 前端控制器
 * </p>
 *
 * @author chair
 * @since 2020-01-30
 */
@LogModule(value = "登录记录管理")
@Api(tags = "登录记录管理")
@RestController
@RequestMapping("/system/loginrecord")
public class LoginrecordController extends BaseController {

	@Autowired
	private ILoginrecordService iLoginrecordService;

	@LogOperation("列表")
	@ApiOperation(value = "列表")
	@PostMapping(value = "/list")
	@RequiresPermissions("00000025")
	public ResponseBean<Map<String, Object>> list(@RequestBody RequestBean requestBean) {
		QueryWrapper<LoginrecordVo> queryWrapper = new QueryWrapper<LoginrecordVo>();
		String uname = (String) requestBean.getParam().get("uname");
		String mobile = (String) requestBean.getParam().get("mobile");
		String loginresult = (String) requestBean.getParam().get("loginresult");
		if (!CommonUtil.isBlank(uname)) {
			queryWrapper.like("u.name", uname);
		}
		if (!CommonUtil.isBlank(mobile)) {
			queryWrapper.like("u.mobile", mobile);
		}
		if (!CommonUtil.isBlank(loginresult)) {
			queryWrapper.like("l.loginresult", loginresult);
		}
		queryWrapper.orderByDesc("l.logintime");
		return responseSuccess(iLoginrecordService.pageVo(requestBean.getPage(), queryWrapper));
	}

	@LogOperation("删除")
	@ApiOperation(value = "删除")
	@PostMapping(value = "/remove")
	@RequiresPermissions("00000025")
	public ResponseBean remove(@RequestBody RequestBean requestBean) {
		List<String> ids = (List<String>) requestBean.getParam().get("ids");
		if (iLoginrecordService.removeByIds(ids)) {
			return responseSuccess();
		} else {
			return responseFail();
		}
	}
}
